<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>行业物料生成</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery-ui/jquery-ui.js"></script>

<script src="${pageContext.request.contextPath}/js/bootstrap/bootstrap.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/bootstrap-table.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/locale/bootstrap-table-zh-CN.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/plugins/tableExport.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/plugins/table-export.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/plugins/jquery.base64.js" type="text/javascript"></script>

<script src="${pageContext.request.contextPath}/ui/layui/layui.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/layui/lay/modules/laydate.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/layui/lay/modules/layer.js" type="text/javascript"></script>
 <script src="${pageContext.request.contextPath}/ui/layui/lay/modules/form.js" type="text/javascript"></script>
 <link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/modules/laydate/laydate.css" >
 <link rel="stylesheet" href="${pageContext.request.contextPath}/css/jquery-css/jquery-ui.css">
 <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap-css/bootstrap.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/ui/table/bootstrap-table.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/layui.css" >
<link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/global.css" >
<link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/modules/layer/default/layer.css" >
 <link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/modules/code.css" >


 <style>
  .container{
   	width:85%;
   	
  }
  
  .modal-industry{
  	width:700px;
  }
  .modal-body{
    max-height:700px
  }
   .modal-body-industry{
  	height:450px;
  }
    
 </style>

</head>
<body>
<%@include file="/webpage/frame/top.jsp" %>
<div class="container">
	<div id="topContent" class="layui-form-pane">
		<div class="layui-form-item" style="margin-bottom:0px;">
			<div class="layui-inline">
			      
			      <div class="layui-input-inline">
			        <select id="industrySel" lay-verify="" lay-search style="margin-left:3px;">
			           <option value="">请选择行业</option> 
			        </select>
			      </div>
			</div>	
				
			<input id="promotionPlanName" type="text" class="form-control" placeholder="请输入主营业务" maxlength="18" style="width:280px;margin-left:15px;margin-bottom:15px;"/>
			<button id="createM" class="layui-btn layui-btn-normal layui-btn-radius" style="margin-bottom:15px;" title="根据行业和主营业务，添加">添加主营业务</button>
			<span class="alert"></span>
		</div>
		
		<div class="layui-form-item" style="margin-bottom:0px;">
			<div class="layui-inline">
			     
			      <div class="layui-input-inline">
			        <select id="industrySel2" lay-verify="" lay-search style="margin-left:3px;">
			           <option value="">请选择行业</option> 
			        </select>
			      </div>
			      <div class="layui-input-inline">
			        <select id="mainBussiness" lay-verify="" lay-search style="margin-left:30px;">
			           <option value="">请选择主营业务</option> 
			        </select>
			      </div>
			</div>	
				
			<input id="inverseKeyword" type="text" class="form-control" placeholder="请输入否词" maxlength="18" style="width:280px;margin-left:42px;margin-bottom:15px;"/>
			
			        <select id="matchedPattern" lay-verify="" lay-search style="margin-left:3px;margin-bottom:20px;">
			           <option value="">请选择匹配模式</option> 
			           <option value="精确否词">精确否词</option>
			           <option value="广泛否词">广泛否词</option>
			        </select>
			      
			<button id="addInverse" class="layui-btn layui-btn-normal layui-btn-radius" style="margin-bottom:15px;" title="根据行业和主营业务，生成">添加否词与匹配模式</button>
			<span class="alert2"></span>
		</div>
	</div>		
</div>
<script>
$alert = $('.alert').hide();
$alert2 = $('.alert2').hide();

function loadIndustry() {
	$.get("${pageContext.request.contextPath}/industryController.do?getAllIndustry",
			function(result){
		      var data = $.parseJSON(result);			     
		       for(i=0;i<data.length;i++){				    	  
		    	  $("#industrySel").append("<option value='"+data[i]["id"]+"'>"+data[i]["industry"]+"</option>");
		    	  $("#industrySel2").append("<option value='"+data[i]["id"]+"'>"+data[i]["industry"]+"</option>");
		       }				    	
			}					
	);   
} 
$(function() {
	   //加载全部行业
	   loadIndustry();
	   
	     
	   
}); 

$("#createM").click(
		function () {			
			var industryId = $("#industrySel").val();
			var industryId2 = $("#industrySel2").val();
			var industryName = $("#industrySel option:selected").text();
			var mainBussiness = $("#promotionPlanName").val();
			if(industryId==""){
				showAlertModal('请选择行业', 'danger');
			}else if(mainBussiness==""){
				showAlertModal('输入主营业务', 'danger');
			}else{							
			$.get(
				'${pageContext.request.contextPath}/materialController.do?addMainBussiness',
						{
							industryId:industryId,
							industryName:industryName,
							mainBussiness:mainBussiness,
						},
						function(result){
							var data = $.parseJSON(result);	
							alert(data);
							
							if(industryId==industryId2){
							$.get(
									'${pageContext.request.contextPath}/materialController.do?getMainBussinessByIndustryId',
											{industryId:industryId},
											function(result){
												var data = $.parseJSON(result);
												
													$("#mainBussiness").append("<option value='"+data[data.length-1]["id"]+"'>"+data[data.length-1]["mainBussiness"]+"</option>");
												
												
											}
											);
							}
						}
			);
			}
		}
	);
	
$("#addInverse").click(
		function () {			
			var industryId = $("#industrySel2").val();
			var industryName = $("#industrySel option:selected").text();
			var mid = $("#mainBussiness").val();
			var mainBussiness = $("#mainBussiness option:selected").text();
			var inverseKeyword = $("#inverseKeyword").val();
			var matchedPattern = $("#matchedPattern").val();
			if(industryId==""){
				showAlertModal2('请选择行业', 'danger');
			}else if(mainBussiness==""){
				showAlertModal2('请选择主营业务', 'danger');
			}else if(inverseKeyword==""){
				showAlertModal2('请输入否词', 'danger');
			}else if(matchedPattern==""){
				showAlertModal2('请选择匹配模式', 'danger');
			} 
			else{							
			$.get(
				'${pageContext.request.contextPath}/materialController.do?addInverse',
						{
							industryId:industryId,
							industryName:industryName,
							mid:mid,
							mainBussiness:mainBussiness,
							inverseKeyword:inverseKeyword,
							matchedPattern:matchedPattern
						},
						function(result){
							var data = $.parseJSON(result);	
							alert(data);
						}
			);
			}
		}
	);
	
	$("#industrySel2").change(
			
			function(){
				var industryId = $("#industrySel2").val();
				$.get(
						'${pageContext.request.contextPath}/materialController.do?getMainBussinessByIndustryId',
								{industryId:industryId},
						function(result){
									$("#mainBussiness").empty();
									 $("#mainBussiness").append("<option value=''>请选择主营业务</option>");
							var data = $.parseJSON(result);	
							for(i=0;i<data.length;i++){	
								
								
						    	  $("#mainBussiness").append("<option value='"+data[i]["id"]+"'>"+data[i]["mainBussiness"]+"</option>");
						    	 
						       }	
						}				
				);
			}
	);
	
function showAlertModal(title, type) {   	
   	$alert.attr('class', 'alert alert-' + type || 'success')
             .html('<i class="glyphicon glyphicon-check"></i> ' + title).show();
   	 setTimeout(function () {
   		 	$alert.hide();
        }, 3000);      
   }  
function showAlertModal2(title, type) {   	
   	$alert2.attr('class', 'alert alert-' + type || 'success')
             .html('<i class="glyphicon glyphicon-check"></i> ' + title).show();
   	 setTimeout(function () {
   		 	$alert2.hide();
        }, 3000);      
   } 

</script>
</body>
</html>